<?php
		/*$mPDF1 = Yii::app()->ePdf->mpdf();
 
        # You can easily override default constructor's params
        */$mPDF1 = Yii::app()->ePdf->mpdf('c','A4','','',7,7,30,40,15,5);
 
        # render (full page)
        //$mPDF1->WriteHTML($this->render('viewPDF', array(), true));
 
        # Load a stylesheet
        $stylesheet = file_get_contents(Yii::getPathOfAlias('webroot.css') . '/pdf.css');
        $mPDF1->WriteHTML($stylesheet, 1);
        $mPDF1->showImageErrors = true;
 
        # renderPartial (only 'view' of current controller)
		
		//--------------------------------------------------------------------------------------------------------
				
		foreach($modelHeader as $mdl1){
			$Qu_no = $mdl1->quotation_no;
			$Qu_cust= $mdl1->Customer->customer;
			$Qu_att= $mdl1->attention;
			//$PO_address= $mdl1->address;
			$Qu_project= $mdl1->project;
			$Qu_reff= $mdl1->reff;
			$Qu_date= $mdl1->date;
			$Qu_curr= $mdl1->currency;
			$Qu_disc= $mdl1->discount;
			$Qu_delivery= $mdl1->delivery;
			$Qu_pay= $mdl1->payment;
			$Qu_valid= $mdl1->validity;
		}
                $Cust_address = Customer::model()->find('customer=:customer',array(':customer'=>$Qu_cust));

                $currency='  ( $ )';
                $tempCurr=1;
                $tempCurr*=FormatingNumber::currency($Qu_curr);
				if($Qu_curr=="IDR"){
					$currency='  ( Rp )';
				}
		//if()
		//$month=
		
		$pdf='
		
<style>
.test {
	border:0.1mm solid #220044; 
}
</style>
			
<!--mpdf
<htmlpageheader name="myHTMLHeader1">
<img src="images/bra_int.jpg" height="100" width="130">
</htmlpageheader>

<htmlpagefooter name="myHTMLFooter">
<table style="font-size: 8pt;" width=100%>
	<tr>
		<td>
		<center>
			<b>PT. Bralink Intertrade</b> <br>
			jl. Raya Paso No.20,Jagakarsa, Jakarta Selatan - Indonesia 12620 <br>
			Phone: +62-21 788 33 279, +62-21 788 40 659, Fax: +62-21 788 30 341<br>
			Website : www.ledlight.co.id
		</center>
	</tr>
</table>
</htmlpagefooter>
mpdf-->

<!-- set the headers/footers - they will occur from here on in the document -->
<!--mpdf
<sethtmlpageheader name="myHTMLHeader1" page="O" value="on" show-this-page="1" />
<sethtmlpagefooter name="myHTMLFooter" page="O" value="on" show-this-page="1" />
mpdf-->

	<table width="100%">
		<tr> <td align="center" style="font-family: Arial;vertical-align:bottom ;font-size:18pt;"><b>PT. BRALINK INTERTRADE</b></td> </tr>
	</table>
	<br><br>
	<table width="100%">
		<tr>
			<td style="padding-left:35px" align="left" width="15%">To </td>
			<td width="50%">: '.$Qu_cust.'</td>
			
			<td width="13%">Quotation No.</td>
			<td>: '.$Qu_no.'</td>
		</tr>
		<tr>
			<td  style="padding-left:35px">Attention </td>
			<td>: '.$Qu_att.'</td>
			<td>Date</td>
			<td>: '.date('d M Y', strtotime($Qu_date)).'</td>
		</tr>
		<tr>
			<td style="padding-left:35px" rowspan="3">Address </td>
			<td>: '.$Cust_address->address.'</td>';
if($Qu_project!=''){					
	$pdf.='	<td>Project</td>
			<td>: '.$Qu_project.'</td>';
		}
	$pdf.='<tr>
			<td>&nbsp;</td>';
if($Qu_project!=''){								
	$pdf.='	<td>Reff</td>
			<td>: '.$Qu_reff.'</td>
		</tr>';
	}			
			
	$pdf.='	</tr>
	</table>
	
	<div class="titlePO">
		QUOTATION<br>
	</div>
	
	<table class="tableView" width="100%">
		<tr class="rowView"  bgcolor="#66CC99">
			<td id="row2" class="columnView">No.</td>
			<td id="row2" class="columnView">PN</td>
			<td id="row2" class="columnView">Description</td>
			<td id="row2" class="columnView">Additional</td>
			<td id="row2" class="columnView">QTY</td>
			<td id="row2" class="columnView">UOM</td>
			<td id="row2" class="columnView">Unit'.$currency.'</td>
			<td id="row2" class="columnView">Total'.$currency.'</td>
		</tr>';
		$grandTotal=0;
		$tempTotal=0;
		$x=1;
		foreach($modelDetail as $mdlDtl){
			$tempDetail=Product::model()->
				  find('product_pn=:product_pn',array(':product_pn'=>$mdlDtl->product_pn));
			$tempTotalItem= $tempDetail->unit_sell*$mdlDtl->qty;
			$tempTotal+=$tempTotalItem;
			
	 $pdf.='<tr>
			<td id="u_row2" class="columnView">'.$x.'</td>
			<td id="u_row2" class="columnView">'.$mdlDtl->product_pn.'</td>
			<td class="columnView"> <b>Lumens</b>: '.$tempDetail->lumens.'<br/> <b>Universal Input</b>: '
			.$tempDetail->universal_input.'<br/> <b>Wattage</b>: '
			.$tempDetail->wattage.'<br/> <b>CCT</b>: '
			.$tempDetail->cct.'<br/> <b>Warranty</b>: '
			.$tempDetail->warranty.' yr(s)<br/> <b>Additional</b>: '
			.'</td>
			<td id="u_row2" class="columnView">'.$mdlDtl->additional.'</td>
			<td id="u_row2" class="columnView">'.$mdlDtl->qty.'</td>
			<td id="u_row2" class="columnView">'.$mdlDtl->uom.'</td>
			<td id="u_row2" class="columnView">'.number_format($tempDetail->unit_sell*$tempCurr,2,'.',',').'</td>
			<td id="u_row2" class="columnView">'.number_format($tempTotalItem*$tempCurr,2,'.',',').'</td>
		</tr>';
		$x++;
		}
		$disc=$tempTotal*($Qu_disc/100);
		$ppn=($tempTotal-$disc)*0.1;
		$grandTotal=$tempTotal-$disc+$ppn;
		
$pdf.='	<tr class="rowView">
			<td rowspan="4" colspan="6">In Words: <br> <b>'.NumberText::makewords(($grandTotal*$tempCurr),$currency).'</b></td>
			<td id="row4" class="columnView">Total'.$currency.'</td>
			<td id="row4">'.number_format($tempTotal*$tempCurr,2,'.',',').'</td>
		</tr>';
if($Qu_disc!=0){		
$pdf.='	<tr class="rowView">
			<td id="row4" class="columnView">Disc.'.$currency.'</td>
			<td id="row4">'.$Qu_disc.'%</td>
		</tr>';
	}
$pdf.='	<tr class="rowView">
			<td id="row4" class="columnView">PPN 10%'.$currency.'</td>
			<td id="row4">'.number_format($ppn*$tempCurr,2,'.',',').'</td>
		</tr>
		<tr class="rowView">
			<td id="row4" class="columnView">Grand Total'.$currency.'</td>
			<td id="row4">'.number_format($grandTotal*$tempCurr,2,'.',',').'</td>
		</tr>
	</table>
	
	<div>
		<a href=""><b>TERM & CONDITION</b></a><br>
		<table>
			<tr><td>1. Price</td><td>: Quoted in <b>'.$Qu_curr.'</b> on Price unit basis with PPn included</td></tr>
			<tr><td>2. Delivery</td><td>: '.$Qu_delivery.', upon received to order & DP</td></tr>
			<tr><td>3. Payment</td><td>: '.$Qu_pay.'</td></tr>
			<tr><td>4. Validity</td><td>: '.$Qu_valid.' days</td></tr>
		</table>
		
	</div>
	<br/><br/>
	<div class="signImage">';
	if(is_null($user->sign)){
$pdf.='	<img  src="images/uploads/'.$user->sign.'" width="210px" height="130px"/>';
	}else{
		$pdf.='<table>
				<tr><td>Best regard,</td></tr>
			    <tr><td><b>PT. BRALINK INTERTRADE</b> <br><br><br><br><br><br><br></td></tr>
			    <tr><td align=center>'.Yii::app()->user->fullName.'</td></tr>
			  </table>';
	}
$pdf.='</div>
		';
		
		//--------------------------------------------------------------------------------------------------------
        $mPDF1->WriteHTML($pdf);
        $mPDF1->AddPage();
 
        # Renders image
        //$mPDF1->WriteHTML(CHtml::image(Yii::getPathOfAlias('webroot.css') . '/bg.gif' ));
 
        # Outputs ready PDF
		$mPDF1->SetDisplayMode('fullpage');
        //$mPDF1->Output('quotation_test.pdf','D');
		$mPDF1->Output();
		exit;
/*ob_start(); 

// Function Date
$day = date('d');
$month = date('m');
$year = date('Y');

switch ($month)
{ 
case 1: $month = "January"; break;
case 2: $month = "February"; break;
case 3: $month = "March"; break;
case 4: $month = "April"; break;
case 5: $month = "May"; break;
case 6: $month = "June"; break;
case 7: $month = "July"; break;
case 8: $month = "August"; break;
case 9: $month = "September"; break;
case 10: $month = "October"; break;
case 11: $month = "November"; break;
case 12: $month = "December"; break;
}

echo "Hello World
Today is $month $day, $year";

$html = ob_get_contents();
ob_end_clean();
//Here convert the encode for UTF-8, if you prefer the ISO-8859-1 just change for $mpdf->WriteHTML($html);
$mPDF1->WriteHTML(utf8_encode($html)); 

$content = $mPDF1->Output('', 'S');

$content = chunk_split(base64_encode($content));
$mailto = 'dolyhanly@gmail.com';
$from_name = 'doly hanly';
$from_mail = 'dolyhanly@gmail.com';
$replyto = 'dolyhanly@yahoo.com';
$uid = md5(uniqid(time())); 
$subject = 'Your e-mail subject here';
$message = 'Your e-mail message here';
$filename = 'filename.pdf';

$header = "From: ".$from_mail." \r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";


//mail($mailto,$subject,$header,$header2, "-r".$from_mail);

mail($mailto,$subject,"",$header );
$mPDF1->Output($filename ,'I');
exit;*/
?>